package com.publicize.controller;


import com.publicize.commom.commonutils.Result;
import com.publicize.service.ModulePictureService;
import com.publicize.service.OssService;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 投稿图片表 前端控制器
 * </p>
 *
 * @author bs
 * @since 2021-03-10
 */
@RestController
@RequestMapping("/oss")
@CrossOrigin
public class OssController {
    @Resource
    private OssService ossService;
    @Resource
    private ModulePictureService modulePictureService;
    //上传头像
    @PostMapping("addAvatar")
    public Result addAvatar(@RequestParam("multipartFile") MultipartFile multipartFile){
        String url = ossService.uploadFileAvatar(multipartFile);
        String fileName = ossService.returnfileName();
        return Result.ok().data("url",url).data("fileName",fileName);
     }
     //删除头像
    @DeleteMapping("deleteAvatar")
    public Result deleteAvatar(@RequestBody String filename){
        System.out.println(filename);
         ossService.deleteFileAvatar(filename);
         return Result.ok();
    }
     //上传多个图片
     @PostMapping("addPicture")
     public Result addPicture(MultipartFile[] file){
         List<String> urls = modulePictureService.addPicture(file);
         return Result.ok().data("urls",urls);
     }

}

